package com.sky.controller.admin.user;

import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.UserOrderService;
import com.sky.vo.OrderSubmitVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/order")
public class UserOrderController {

    @Autowired
    private UserOrderService userOrderService;

    /**
     * 用户下单
     *
     * @param ordersSubmitDTO
     * @return {@link Result}<{@link ?}>
     */
    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        OrderSubmitVO orderSubmitVO = userOrderService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    /**
     * 历史订单查询
     *
     * @return {@link Result}
     */
    @GetMapping("/historyOrders")
    public Result<PageResult> historyOrders(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = userOrderService.historyOrders(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 查询订单详情
     *
     * @param id
     * @return {@link Result}
     */
    @GetMapping("/orderDetail/{id}")
    public Result<Orders> orderDetail(@PathVariable Long id){
        Orders orders = userOrderService.orderDetail(id);
        return Result.success(orders);
    }

    /**
     * 取消订单
     *
     * @param id
     * @return {@link Result}
     */
    @PutMapping("/cancel/{id}")
    public Result<?> cancel(@PathVariable Long id){
        userOrderService.cancel(id);
        return Result.success();
    }

    /**
     * 再来一单
     *
     * @param id
     * @return {@link Result}
     */
    @PostMapping("/repetition/{id}")
    public Result<?> repetition(@PathVariable Long id){
        userOrderService.repetition(id);
        return Result.success();
    }

    /**
     * 模拟支付完成接口
     *
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/paySuccess/{number}")
    public Result<?> paySuccess(@PathVariable String number){
        userOrderService.paySuccess(number);
        return Result.success();
    }

    /**
     * 催单
     *
     * @param id
     * @return {@link Result}<{@link ?}>
     */
    @GetMapping("/reminder/{id}")
    public Result<?> reminder(@PathVariable Long id){
        userOrderService.reminder(id);
        return Result.success();
    }
}
